<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>子传父</title>
    <script src="./js/vue2.js"></script>
</head>
<body>
    <div id="app">
        <father></father>
    </div>
    <template id="father">
        <div class="father">
            <p>我是父组件，我叫{{fname}}</p>
            <p>今天我儿子告诉我，他的女朋友的名字叫做{{erxifu}}</p>
            <son @getname='ok'></son>
        </div>
    </template>
    <template id="son">
        <div class="son">
            <p>我是子组件，我叫{{sname}}</p>
            <p>我今天要告诉我我父亲，我女朋友的名字叫{{gfname}}</p>
            <button @click="tellname" >点击</button>
        </div>
    </template>
</body>
<script>
    Vue.component('father',{
        template:"#father",
        data(){
            return {
                fname:'father',
                erxifu:'??'

            }
        },
        methods:{
            ok(data){
                console.log(data)
                this.erxifu=data;
            }
        },
        components: {
            'son':{
                template:'#son',
                data(){
                    return {
                        sname:'jack',
                        gfname:'翠花'
                    }
                },
                methods: {
                    tellname(){
                        console.log(this.$emit)
                        this.$emit('getname',this.gfname)
                    }
                }
            }
        }
    })
    var vm = new Vue({
        el:"#app",
        data:{

        }
    })
</script>
</html>